#include <Windows.h>
#include "ImageBuffer.h"

namespace Graphics
{
	ImageBuffer::ImageBuffer(int width, int height)
	{
		if(width > 0 && height > 0)
		{
			this->_width = width;
			this->_height = height;

			this->_data = new Pixel[_width * _height];
			ZeroMemory(_data, sizeof(_data) * (_width * _height));

			//for(int i = 0; i < _width * _height; i++)
			//{
			//	_data[i].Attributes = 0x00;
			//	_data[i].Char.AsciiChar = ' ';
			//}
		}
		else
			throw 123;
	}

	ImageBuffer::~ImageBuffer()
	{ delete [] _data; }

	void ImageBuffer::setData(int x, int y, Pixel& data)
	{
		if(_data != 0)
		{
			int index = x * _width + y;

			if(index >= _width * _height)
				return;
			else
			{
				_data[index].Attributes = data.Attributes;
				_data[index].Char = data.Char;
			}
		}
	}

}